package controller;

import dao.StatisticsDAO;
import java.util.Map;

/**
 * 统计控制器
 */
public class StatisticsController {
    private StatisticsDAO statisticsDAO;

    public StatisticsController() {
        this.statisticsDAO = new StatisticsDAO();
    }

    /**
     * 获取用户统计数据
     */
    public Map<String, Object> getUserStatistics(int userId, boolean isAdminMode) {
        try {
            if (isAdminMode) {
                return statisticsDAO.getSystemStatistics();
            } else {
                return statisticsDAO.getUserStatistics(userId);
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("获取统计数据失败: " + e.getMessage());
        }
    }

    /**
     * 获取系统统计数据
     */
    public Map<String, Object> getSystemStatistics() {
        try {
            return statisticsDAO.getSystemStatistics();
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("获取系统统计数据失败: " + e.getMessage());
        }
    }

    /**
     * 获取座位使用率统计
     */
    public Map<String, Object> getSeatUtilizationStats() {
        try {
            return statisticsDAO.getSeatUtilizationStats();
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("获取座位使用率统计失败: " + e.getMessage());
        }
    }

    /**
     * 获取时间段使用统计
     */
    public Map<String, Object> getTimeSlotStats() {
        try {
            return statisticsDAO.getTimeSlotStats();
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("获取时间段统计失败: " + e.getMessage());
        }
    }

    /**
     * 获取楼层使用统计
     */
    public Map<String, Object> getFloorStats() {
        try {
            return statisticsDAO.getFloorStats();
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("获取楼层统计失败: " + e.getMessage());
        }
    }

    /**
     * 获取用户预约趋势数据
     */
    public Map<String, Object> getUserTrendData(int userId, String period) {
        try {
            return statisticsDAO.getUserTrendData(userId, period);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("获取预约趋势数据失败: " + e.getMessage());
        }
    }

    /**
     * 获取用户时间段偏好数据
     */
    public Map<String, Object> getUserTimeSlotData(int userId, String period) {
        try {
            return statisticsDAO.getUserTimeSlotData(userId, period);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("获取时间段数据失败: " + e.getMessage());
        }
    }

    /**
     * 获取用户考勤统计数据
     */
    public Map<String, Object> getUserAttendanceData(int userId, String period) {
        try {
            return statisticsDAO.getUserAttendanceData(userId, period);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("获取考勤数据失败: " + e.getMessage());
        }
    }

    /**
     * 获取用户信誉分
     */
    public int getUserCreditScore(int userId) {
        try {
            return statisticsDAO.getUserCreditScore(userId);
        } catch (Exception e) {
            e.printStackTrace();
            return 100; // 默认返回初始分数
        }
    }
}
